import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../controllers/tabs_controller.dart';

class TabsView extends GetView<TabsController> {
  const TabsView({super.key});

  @override
  Widget build(BuildContext context) {
    return Obx(
      () => Scaffold(
        body: PageView(
          controller: controller.pageController,
          // 禁止左右滑动
          physics: const NeverScrollableScrollPhysics(),
          // children: [controller.pages[controller.currentIndex.value]],
          // 滑动
          children: controller.pages,
          onPageChanged: (index) {
            controller.currentIndex.value = index;
          },
        ),

        // 配置底部TabBar
        bottomNavigationBar: BottomNavigationBar(
          fixedColor: Colors.red,
          //选中的颜色
          currentIndex: controller.currentIndex.value,
          type: BottomNavigationBarType.fixed,
          //如果底部有4个或者4个以上的
          onTap: (index) {
            controller.setCurrentIndex(index);

            //   jumpToPage跟随点击改变
            controller.pageController.jumpToPage(index);
          },
          items: const [
            BottomNavigationBarItem(icon: Icon(Icons.home), label: '首页'),
            BottomNavigationBarItem(icon: Icon(Icons.category), label: '分类'),
            BottomNavigationBarItem(
              icon: Icon(Icons.room_service),
              label: '服务',
            ),
            BottomNavigationBarItem(
              icon: Icon(Icons.shopping_cart),
              label: '购物车',
            ),
            BottomNavigationBarItem(icon: Icon(Icons.people), label: '用户'),
          ],
        ),
      ),
    );
  }
}
